﻿using System.Collections.Generic;
using System.Linq;

namespace _24_C_中的List集合的去重问题
{
    internal class Program
    {
        static void Main(string[] args)
        {
            Console.Title = "C#中的List集合的去重问题";

            //List<int> ints = new List<int>() { 1, 2, 3, 4, 5, 6, 7, 7, 5, 3, 9, 1, 2, 4, 8, 5, 4 };

            //List<int> tempints = ints.Distinct<int>().ToList();

            //foreach (int i in tempints)
            //{
            //    Console.WriteLine(i);
            //}

            //List<string> list = new List<string>() { "a", "b", null,"v", "c", "c", "d", "d" };

            //List<string> templist = list.Distinct<string>().ToList();

            //foreach (string i in templist)
            //{
            //    Console.WriteLine(i);
            //}

            //过滤不了
            List<Person> people = new List<Person>()
            {
                new Person() { Id=1,Name="李四",Age=20},
                new Person() { Id=1,Name="李四",Age=20}
            };
            List<Person> temppeople = people.Distinct<Person>(new TestComper()).ToList();

            foreach (Person person in temppeople)
            {
                Console.WriteLine($"{person.Id}-{person.Name}-{person.Age}");
            }

            Console.ReadKey();
        }
    }
}
